﻿
using System.Collections.ObjectModel;

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;
using System.Linq;
using System.Collections.Generic;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 绘制折线
    /// </summary>
    [Filter("绘制折线", FilterType.Draw)]
    public class DrawPolylines : FilterBase
    {
        /// <summary>
        /// 粗细
        /// </summary>
        [InputParameter("颜色")]
        public Scalar Color { get; set; }
        /// <summary>
        /// 是否闭合
        /// </summary>
        [InputParameter("是否闭合")]
        public bool IsClose { get; set; }
        /// <summary>
        /// 坐标点
        /// </summary>
        [InputParameter("坐标点")]
        public ObservableCollection<ObservableCollection<CVPoint>> Points { get; set; } = new ObservableCollection<ObservableCollection<CVPoint>>();
        /// <summary>
        /// 粗细
        /// </summary>
        [InputParameter("粗细")]
        public int Thickness { get; set; } = 1;
        /// <summary>
        /// 线段类型
        /// </summary>
        [InputParameter("线段类型", ParameterType.Optional)]
        public LineTypes LineType { get; set; } = LineTypes.Link8;
        /// <summary>
        /// 偏移量
        /// </summary>
        [InputParameter("缩放值", ParameterType.Optional)]
        public int Shift { get; set; } = 0;


        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
            if (Points.Count>0)
            {
                var c = Points.Select(p => p.Select(d => (Point)d).ToArray()).ToArray();

                Cv2.Polylines(mat, c, IsClose, Color, Thickness, LineType, Shift);
            }

            return ResultData<Mat>.Accept(TextResource.draw_success, mat);

        }
    }
}
